import { request } from '@/utils/request-fetch'
const VUE_APP_BASE_API = process.env.VUE_APP_BASE_API
// 获取优惠券详情
export function getSceneCouponDetail (data) {
  return request('POST', VUE_APP_BASE_API + '/api/v1/coupon/check_can_draw', data, { authBear: true })
}
export async function getSceneCouponDetailByIds (ids) {
  const queues = ids.map((v) => getSceneCouponDetail({ coupon_id: Number(v) }))
  const res = await Promise.all(queues)
  const acts = []
  res.forEach((v) => {
    const data = v.data?.data
    if (data && ['ok', 'draw_valid'].includes(data.sub_code) && data.detail) {
      acts.push(data.detail)
    }
  })
  if (acts.length) {
    return acts
  }
  return null
}

// 批量领取优惠券
export function useSceneCoupon (data) {
  return request('POST', VUE_APP_BASE_API + '/api/v1/coupon/multi_draw', data, { authBear: true })
}
